package com.zycx.system.user.controller;

import com.zycx.common.annotation.CurrentSignInUser;
import com.zycx.common.annotation.IgnoreSecurity;
import com.zycx.interceptor.CurrentUser;
import com.zycx.common.result.ServerResponse;
import com.zycx.system.user.entity.User;
import com.zycx.system.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * Created by zycx on 2018-12-04 21:36
 * Created with IntelliJ IDEA.
 */
@Controller
@RequestMapping("/api/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    /**
     *    注册
     * @param user 用户信息
     */
    @PostMapping("")
    @IgnoreSecurity
    @ResponseBody
    public ServerResponse saveUser(@RequestBody User user){
        return userService.saveUser(user);
    }

    /**
     *  登陆
     * @param user 用户
     * @return  token
     */
    @PostMapping("/login")
    @ResponseBody
    @IgnoreSecurity
    public ServerResponse login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping("/in")
    @ResponseBody
    public ServerResponse user(){
        User user = new User();
        user.setId(CurrentUser.getUserID());
        user.setUserName(CurrentUser.getUserName());
        user.setName(CurrentUser.getName());
        user.setStatus(CurrentUser.getStatus());
        user.setSuperAdmin(CurrentUser.getSuperAdmin());
        return ServerResponse.successData(user);
    }

    @PostMapping("/info")
    @ResponseBody
    public ServerResponse userInfo(@CurrentSignInUser User user){
        return ServerResponse.successData(user);
    }

}
